
import store from '../store/index.js'
import {userInfoApi,userRelationApi} from '../api/index.js'

//微信登录or微信获取用户信息
export const uniLogin = function () {
	return new Promise((resolve, reject) => {
		uni.login({
			provider: 'weixin',
			success: (loginRes) => {
				resolve(loginRes)
			},
			fail: (loginErr) => {
				reject({
					message: '微信授权失败~'
				})
			}
		});
	})
};

export const uniUserInfo = function () {
	return new Promise((resolve, reject) => {
		uni.getUserInfo({
			provider: 'weixin',
			success: (infoRes) => {
				resolve(infoRes)
			},
			fail: (infoErr) => {
				reject({
					message: '获取用户信息失败'
				})
			}
		});
	})
};

export const uniAppleLogin = function () {
	return new Promise((resolve, reject) => {
		uni.login({
			provider: 'apple',
			success: (loginRes) => {
				resolve(loginRes)
			},
			fail: (loginErr) => {
				console.log(loginErr)
				reject({
					message: '苹果授权失败~'
				})
			}
		});
	})
};

export const ifLoginFun = function () {
	if(store.state.userToken === ''){
		uni.showToast({
			title:'未登录,正在跳转登录',
			icon:'none'
		})
		
		setTimeout(()=> {
			uni.navigateTo({
				url:'/pages/user/login'
			})
		}, 1000);
		return false
	}else{
		return true
	}
};